import requests

from src.tools.dms_operator import DMSOperator

correct_url = "http://192.168.10.126:8085/"


def correct(file_id):
    dms_op =DMSOperator()
    file_json_body = dms_op.get_jsonfile(file_id)
    pageCount = file_json_body.get("pageCount")
    paragraphInfos = file_json_body.get("paragraphInfos")
    tableInfos = file_json_body.get("tableInfos")
    # print(file_json_body)
    res = requests.post(f"{correct_url}/correct/1",json={"pageCount":pageCount,"paragraphInfos":paragraphInfos,"tableInfos":tableInfos})
    correct_res = res.json()
    edit_file = {
        "fileId":file_id,
        "editContentInfos":[]
    }
    for i in correct_res["paragraphInfos_corrected"]:
        if i["text_corrected"].strip():
            if i["text"].strip() != i["text_corrected"].strip():
                edit_file["editContentInfos"].append(
                    {"index":i["index"],
                     "sectionIndex":i["sectionIndex"],
                     "bodyChildIndex":i["bodyChildIndex"],
                     "operationType":0,
                     "documentObjectType":0,
                     "content":i["text_corrected"].strip()
                     }
                )
    res_edit = dms_op.post_edit_file(edit_file)
    # 调用修改对比接口
    res2 = dms_op.post_compair(file_id,res_edit["data"])
    print(res2)

if __name__ == "__main__":
    correct("Files\\202411\\20241106102714hEa8FokpeDB线葡萄糖注射液原版2-修改模板.docx")